﻿using System;
using System.Configuration; 

namespace BuilderPattern
{
    class Program
    {
        public static void Main(string[] args)
        {
            Builder builder = new USA("黑皮肤", "美国人", "英语");
            Director director = new Director(builder);
            People product = director.Construct();
            Console.Write("\r\n");

            Builder builder1 = new USA("白皮肤", "英国人", "日语");
            Director director1 = new Director(builder1);
            People product1 = director1.Construct();
            Console.ReadKey();
        }
    }

    /// <summary>
    /// 创建抽象类
    /// </summary>
    public abstract class Builder
    {
        protected People people = new People();
        public abstract void SetCountry();
        public abstract void SetSpeak();
        public abstract void SetSkinColor();

        public People getResult()
        {
            return people;
        }
    }

    /// <summary>
    /// 被创建的对象，对象会出现局部的不同，
    /// </summary>
    public class People
    {
        public People()
        {
            Console.Write("我们都是人，但是");
        }
    }

    public class USA : Builder
    {
        private string _country;
        private string _speak;
        private string _skincolor;
        public USA(string skincolor, string country, string speak)
        {
            this._country = country;
            this._skincolor = skincolor;
            this._speak = speak;
        }
        public override void SetSkinColor()
        {
            Console.Write(_skincolor + "的");
        }
        public override void SetCountry()
        {
            Console.Write(_country);
        }

        public override void SetSpeak()
        {
            Console.Write("讲" + _speak);
        }
    }

    public class UK : Builder
    {
        private string _country;
        private string _speak;
        private string _skincolor;
        public UK(string skincolor, string country, string speak)
        {
            this._country = country;
            this._skincolor = skincolor;
            this._speak = speak;
        }
        public override void SetSkinColor()
        {
            Console.Write(_skincolor + "的");
        }
        public override void SetCountry()
        {
            Console.Write(_country);
        }

        public override void SetSpeak()
        {
            Console.Write("讲" + _speak);
        }
    }

    /// <summary>
    /// 执行者,创建对象
    /// </summary>
    public class Director
    {
        private Builder builder;
        public Director(Builder bu)
        {
            this.builder = bu;
        }
        public People Construct()
        {
            builder.SetSkinColor();
            builder.SetCountry();
            builder.SetSpeak();
            return builder.getResult();
        }
    }


}
